﻿using Microsoft.Extensions.Options;
using Minotaur.App.Domains.Enum;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Minotaur.App.Core
{
    /// <summary>
    /// 枚举转换
    /// </summary>
    public static  class EnumConvert
    {/// <summary>
     /// 字符串转枚举
     /// </summary>
     /// <typeparam name="T"></typeparam>
     /// <param name="value"></param>
     /// <returns></returns>
        public static T ConvertEnumEvent<T>(this string value) where T : Enum
        {
            if (string.IsNullOrEmpty(value)) return default(T);
            return (T)Enum.Parse(typeof(T), value.Replace("-", "_"), true);
        }
        /// <summary>
        /// 枚举转字符串
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="value"></param>
        /// <returns></returns>
        public static string ConvertEnumToSringEvent<T>(this T value) where T : Enum
        {
            if (value == null) return "";
            string str = Enum.GetName(typeof(T), value) + "";
            return str == "zh_cn" ? "zh-cn" : str;
        } 
    }
}
